home *** CD-ROM | disk | FTP | other *** search
-
- package sub_arctic.lib;
-
- import sub_arctic.lib.sub_arctic_error;
- import sub_arctic.output.loaded_image;
- import sub_arctic.output.drawable;
- import sub_arctic.input.pressable;
- import sub_arctic.input.move_draggable;
- import sub_arctic.input.event;
- import sub_arctic.input.user_info_holder;
- import sub_arctic.input.pick_collector;
- import sub_arctic.input.callback_object;
- import java.awt.Point;
-
- /**
- * This class provides a container for dragging. You can put any subtree
- * inside it to make that subtree draggable. The container handles the
- * pick process correctly so that it only initiates a drag if you actually
- * click over an object inside the an object in the sub-tree (not simply
- * anywhere inside the bounds of the container). The container will
- * "shrink-wrap" around the objects it contains, and can optionally draw
- * a bounding rectangle as drag feedback.
- *
- * @author Scott Hudson
- */
- public class drag_container extends shrink_wrap_container
- implements pressable, move_draggable {
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /** Flag bit position for flag indicating whether to do bounding box
- * drag feedback. */
- protected static final int DO_BB_FEEDBACK = DRAW_BORDER << 1;
-
-
- /** Is the object currently set to do bounding box drag feedback? */
- public boolean bounding_box_feedback() {return flag_is_set(DO_BB_FEEDBACK);}
-
-
- /**
- * Set object to do or not do bounding box drag feedback.
- *
- * @param boolean do_bbf passed true if the object should do bounding box
- * feedback during drag.
- */
- public void set_bounding_box_feedback(boolean do_bbf)
- {
- if (flag_is_set(DO_BB_FEEDBACK) != do_bbf)
- {
- set_flag_bit(DO_BB_FEEDBACK, do_bbf);
- damage_self();
- }
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Flag bit position for flag indicating whether we are currently in the
- * middle of a drag.
- */
- protected static final int DOING_DRAG = DO_BB_FEEDBACK << 1;
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /** Object we make callbacks to. */
- protected callback_object _callback_obj = null;
-
- /**
- * Retrieve the object we make callbacks to.
- * @return callback_object the callback object.
- */
- public callback_object callback_obj() {return _callback_obj;}
-
- /**
- * Set the object we make callbacks to.
- * @param callback_object cbo the new callback object.
- */
- public void callback_obj(callback_object cbo) {_callback_obj = cbo;}
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Constant for "move" callback (called on every move, including last).
- * This callback provides a Point object with the position of the container
- * in its parent's coordinates.
- */
- public final static int MOVE_CALLBACK = 0;
-
- /**
- * Constant for "end" callback (called only at end of move).
- * This callback provides a Point object with the position of the container
- * in its parent's coordinates.
- */
- public final static int END_MOVE_CALLBACK = 1;
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * full constructor.
- *
- * @param int x initial x position of the container.
- * @param int y initial y position of the container.
- * @param boolean do_bb_feedback whether we do bounding box feedback.
- * @param callback_object cbo object to make callbacks to.
- */
- public drag_container(
- int x, int y, boolean do_bb_feedback, callback_object cbo)
- {
- super(x,y,2,false);
- set_bounding_box_feedback(do_bb_feedback);
- set_flag_bit(DOING_DRAG, false);
- _callback_obj = cbo;
- }
-
- //had:
- //* @exception general
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Nearly full constructor. This provides a null callback.
- *
- * @param int x initial x position of the container.
- * @param int y initial y position of the container.
- * @param boolean do_bb_feedback whether we do bounding box feedback.
- */
- public drag_container(int x, int y, boolean do_bb_feedback)
- {
- super(x,y,2,false);
- set_bounding_box_feedback(do_bb_feedback);
- set_flag_bit(DOING_DRAG, false);
- _callback_obj = null;
- }
-
- //had:
- //* @exception general
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Handle mouse button press input to the object. Here, we start dragging.
- * @param event evt press event being dispatched.
- * @param Object user_info information provided by this object at pick time
- * (in this case ignored).
- */
- public boolean press(event evt, Object user_info)
- {
- manager.move_drag_focus.set_focus_to(this, evt, new point_info(0,0));
- return true;
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Companion to press(). Here we ignore this.
- * @param event evt release event being dispatched.
- * @param Object user_info information provided by this object at pick time
- */
- public boolean release(event evt, Object user_info)
- {
- return false;
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Handle the start of a drag to the object.
- * @param event evt the event "causing" the start of the drag.
- * @param int x_pos x position of new position (in parent's coords).
- * @param int y_pos y position of new position (in parent's coords).
- * @param int grab_x x position where we started the drag (in local
- * coords).
- * @param int grab_y y position where we started the drag (in local
- * coords).
- * @param Object user_info information provided when this object requested
- * focus.
- * @return boolean indicating whether the input was consumed (in this case it
- * always is).
- */
- public boolean drag_start(
- event evt,
- int x_pos, int y_pos,
- int grab_x, int grab_y,
- Object user_info)
- {
- /* position at x,y */
- set_pos(x_pos, y_pos);
-
- /* remember we are dragging */
- set_flag_bit(DOING_DRAG, true);
-
- /* if we are doing bounding box feedback force a redraw regardless */
- if (bounding_box_feedback()) damage_self();
-
- return true;
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Handle a movement during a drag. Here we just set our position to
- * follow the event location and do the move callback.
- *
- * @param event evt the event "causing" the start of the drag.
- * @param int x_pos x position of new position (in parent's coords).
- * @param int y_pos y position of new position (in parent's coords).
- * @param int start_x x position where we started the drag (in parent's
- * coords).
- * @param int start_y y position where we started the drag (in parent's
- * coords).
- * @param int grab_x x position where we started the grab (in local
- * coords).
- * @param int grab_y y position where we started the grab (in local
- * coords).
- * @param Object user_info information provided when this object requested
- * focus.
- * @return boolean indicating whether the input was consumed (in this case it
- * always is).
- */
- public boolean drag_feedback(
- event evt,
- int x_pos, int y_pos,
- int st_x, int st_y,
- int grab_x, int grab_y,
- Object user_info)
- {
- /* move our position */
- set_pos(x_pos, y_pos);
-
- /* do callback */
- if (callback_obj() != null) {
- callback_obj().callback(this, evt, MOVE_CALLBACK,
- new Point(x_pos, y_pos));
- }
- return true;
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Handle input corresponding to the end of a drag.
- *
- * @param event evt the event "causing" the start of the drag.
- * @param int x_pos x position of new position (in parent's coords).
- * @param int y_pos y position of new position (in parent's coords).
- * @param int start_x x position where we started the drag (in parent's
- * coords).
- * @param int start_y y position where we started the drag (in parent's
- * coords).
- * @param int grab_x x position where we started the grab (in local
- * coords).
- * @param int grab_y y position where we started the grab (in local
- * coords).
- * @param Object user_info information provided when this object requested
- * focus.
- * @return boolean indicating whether the input was consumed (in this case it
- * always is).
- */
- public boolean drag_end(
- event evt,
- int x_pos, int y_pos,
- int st_x, int st_y,
- int grab_x, int grab_y,
- Object user_info)
- {
- boolean result = false;
-
- /* we are done dragging */
- set_flag_bit(DOING_DRAG, false);
- damage_self();
-
- /* let drag_feedback do most of the work */
- result = drag_feedback(evt, x_pos, y_pos, st_x, st_y, grab_x, grab_y,
- user_info);
- /* do ending callback */
- if (callback_obj() != null)
- callback_obj().callback(this, evt, END_MOVE_CALLBACK,
- new Point(x_pos, y_pos));
- return result;
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Determine if this object is "picked" by the the given point. In this
- * case, we are only picked if at least one of our descendents is picked,
- * but we need to be in the pick list before our children so we can
- * intercept input intended for them. To do this, we do a "local" pick
- * within our children, then merge that back into the "real" pick as needed.
- * putting ourselves first then picks from our children.
- *
- * @param int pt_x x of point we are testing for pick.
- * @param int pt_y y of point we are testing for pick.
- * @param pick_collector pick_list the collector for our result.
- */
- public void pick(int pt_x, int pt_y, pick_collector pick_list)
- {
- pick_collector local_pick;
- user_info_holder info;
-
- /* don't pick anything unless we are enabled and its inside our bounds */
- if (enabled() && visible() && picked_by(pt_x, pt_y))
- {
- /* create a new "local" pick collector an do child picks with that */
- local_pick = new pick_collector();
- pick_within_children(pt_x, pt_y, local_pick);
-
- /* insert picks (if we have any) in "real" pick list */
- if (local_pick.num_picks() > 0)
- {
- /* we go before our children */
- pick_list.report_pick(this);
-
- /* report picks from children in order */
- for (int i = 0; i<local_pick.num_picks(); i++)
- {
- info = local_pick.pick(i);
- pick_list.report_pick(info.obj, info);
- }
- }
- }
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Draw the object's current appearance. This draws the children
- * and then the optional border rectangle if we are being dragged.
- * @param drawable d the surface we draw on.
- */
- protected void draw_self_local(drawable d)
- {
- /* let superclass draw any children we have */
- super.draw_self_local(d);
-
- /* optionally draw our border */
- if (bounding_box_feedback() && flag_is_set(DOING_DRAG))
- d.drawRect(0,0,w()-1,h()-1);
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
- }
- /*=========================== COPYRIGHT NOTICE ===========================
-
- This file is part of the subArctic user interface toolkit.
-
- Copyright (c) 1996 Scott Hudson and Ian Smith
- All rights reserved.
-
- The subArctic system is freely available for most uses under the terms
- and conditions described in
- http://www.cc.gatech.edu/gvu/ui/sub_arctic/sub_arctic/doc/usage.html
- and appearing in full in the lib/interactor.java source file.
-
- The current release and additional information about this software can be
- found starting at: http://www.cc.gatech.edu/gvu/ui/sub_arctic/
-
- ========================================================================*/
-